package org.example.Server.controller.paper;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.paper.*;
import org.example.Server.service.paper.PaperPersonalService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教师试卷库
 */
@RestController
@Slf4j
@RequestMapping("/youxich/paper")
public class PaperPersonalController {
    @Autowired
    private PaperPersonalService paperPersonalService;

    /**
     * 添加试卷头
     *
     * @param paperHeader
     * @return
     */
    @PostMapping("/personal")
    public ResultAPI addPaperHeader(@RequestBody PaperHeader paperHeader) {
        return paperPersonalService.addPaperHeader(paperHeader);
    }

    /**
     * 试卷基础编辑回显
     *
     * @param paper_id
     * @return
     */
    @GetMapping("/personal/paperSetting")
    public ResultAPI getPaperSetting(@RequestParam Integer paper_id) {
        return paperPersonalService.getPaperSetting(paper_id);
    }

    /**
     * 试卷基础编辑更新
     *
     * @param paperSetting
     * @return
     */
    @PutMapping("/personal/paperSetting")
    public ResultAPI updatePaperSetting(@RequestBody PaperSetting paperSetting) {
        return paperPersonalService.updatePaperSetting(paperSetting);
    }

    /**
     * 教师获取试卷库的试卷头列表
     *
     * @param tech_id
     * @param direction_id
     * @param difficulty
     * @return
     */
    @GetMapping("/personal")
    public ResultAPI getPaperHeaderLsit(@RequestParam(required = false) Integer tech_id,
                                        @RequestParam(required = false) Integer direction_id,
                                        @RequestParam(required = false) Integer difficulty) {
        return paperPersonalService.getPaperHeaderLsit(tech_id, direction_id, difficulty);
    }

    /**
     * 教师自己在试卷中不通过试题库添加试题
     *
     * @param questionPaper
     * @return
     */
    @PostMapping("/qs")
    public ResultAPI addPaperQsBySelf(@RequestBody PaperQsDTO questionPaper) {
        return paperPersonalService.addPaperQsBySelf(questionPaper);
    }

    /**
     * 教师从试题库中导入题目
     *
     * @param paperQsStoreDTO
     * @return
     */
    @PostMapping("/qs/many")
    public ResultAPI addPaperQsByQuestionStore(@RequestBody PaperQsStoreDTO paperQsStoreDTO) {
        return paperPersonalService.addPaperQsByQuestionStore(paperQsStoreDTO);
    }

    /**
     * 教师通过paper_id获取当前试卷的具体内容
     * 包括：试卷头、试卷每一题到选项、试卷侧边目录栏
     *
     * @param paper_id
     * @return
     */
    @GetMapping("/personal/{paper_id}")
    public ResultAPI getPaperById(@PathVariable Integer paper_id) {
        log.info("paper_id:{}", paper_id);
        return paperPersonalService.getPaperById(paper_id);
    }

    /**
     * 教师更新题型内容：多选题=》自定义为别的=》多选
     *
     * @param paperFormat
     * @return
     */
    @PatchMapping("/personal/qsformat")
    public ResultAPI updateQsformat(@RequestBody PaperFormat paperFormat) {
        return paperPersonalService.updateQsformat(paperFormat);
    }

    /**
     * 教师更新试卷题目分数
     *
     * @param paperQsUpdate
     * @return
     */
    @PatchMapping("/personal/qsmaxscore")
    public ResultAPI updateQsMaxscore(@RequestBody PaperQsUpdate paperQsUpdate) {
        return paperPersonalService.updateQsMaxscore(paperQsUpdate);
    }

    /**
     * 删除试卷（批量）
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/personal/{ids}")
    public ResultAPI deletePapers(@PathVariable List<Integer> ids) {
        return paperPersonalService.deletePapers(ids);
    }

    /**
     * 老师更新试卷的某一题
     *
     * @param paperQsUpdate
     * @return
     */
    @PatchMapping("/personal/qs")
    public ResultAPI updatePaperQs(@RequestBody PaperQsUpdate paperQsUpdate) {
        return paperPersonalService.updatePaperQs(paperQsUpdate);
    }


    /**
     * 删除某试卷中的试题
     * 删除试卷中的试题，但是因为试卷中的题目其实都是复制出来的
     * 所以好像只传qs也可以（那么就可以用删除试题的接口了）
     *（暂定）
     * @param paper_qs_ids
     * @return
     */
    @DeleteMapping("/personal/qs/{paper_qs_ids}")
    public ResultAPI deletePaperQs(@PathVariable List<Integer> paper_qs_ids) {
        return paperPersonalService.deletePaperQs(paper_qs_ids);
    }


}
